<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{block}</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.builtin.functions.html" title="Chapter 7. Built-in Functions">
<link rel="prev" href="language.function.assign.html" title="{assign}">
<link rel="next" href="language.function.call.html" title="{call}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{block}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.assign.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Built-in Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.call.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{block}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.block"></a>{block}</h2></div></div></div>
<p>
   <code class="varname">{block}</code> is used to define a named area of template source for template inheritance.
   For details see section of <a class="link" href="advanced.features.template.inheritance.html" title="Template Inheritance">Template Interitance</a>.
  </p>
<p>
    The <code class="varname">{block}</code> template source area of a child template will replace the correponding areas in the parent template(s).
   </p>
<p>
    Optionally <code class="varname">{block}</code> areas of child and parent templates can be merged into each other. You can append or prepend the parent <code class="varname">{block}</code>
     content by using the <code class="literal">append</code> or <code class="literal">prepend</code> option flag with the childs <code class="varname">{block}</code> definition. With the {$smarty.block.parent} the <code class="varname">{block}</code> content 
    of the parent template can be inserted at any location of the child <code class="varname">{block}</code> content. {$smarty.block.child} inserts the <code class="varname">{block}</code> content of 
    the child template at any location of the parent <code class="varname">{block}</code>.
   </p>
<p><code class="varname">{blocks}'s</code> can be nested.
   </p>
<p><span class="bold"><strong>Attributes:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody><tr>
<td align="center">name</td>
<td align="center">string</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the template source block</td>
</tr></tbody>
</table></div>
<p><span class="bold"><strong>Option Flags (in child templates only):</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Name</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">append</td>
<td>The <code class="varname">{block}</code> content will be be appended to the content of the parent template <code class="varname">{block}</code>
</td>
</tr>
<tr>
<td align="center">prepend</td>
<td>The <code class="varname">{block}</code> content will be prepended to the content of the parent template <code class="varname">{block}</code>
</td>
</tr>
<tr>
<td align="center">hide</td>
<td>Ignore the block content if no child block of same name is existing.</td>
</tr>
<tr>
<td align="center">nocache</td>
<td>Disables caching of the <code class="varname">{block}</code> content</td>
</tr>
</tbody>
</table></div>
<div class="example">
<a name="id366728"></a><p class="title"><b>Example 7.15. Simple <code class="varname">{block}</code> example</b></p>
<div class="example-contents">
<p>parent.tpl</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{block name="title"}Default Title{/block}&lt;/title&gt;
    &lt;title&gt;{block "title"}Default Title{/block}&lt;/title&gt;  {* short-hand  *}
  &lt;/head&gt;
&lt;/html&gt;

  </pre>
<p>child.tpl</p>
<pre class="programlisting">

{extends file="parent.tpl"} 
{block name="title"}
Page Title
{/block}

  </pre>
<p>The result would look like</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Page Title&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

</pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id366772"></a><p class="title"><b>Example 7.16. Prepend <code class="varname">{block}</code> example</b></p>
<div class="example-contents">
<p>parent.tpl</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{block name="title"}Title - {/block}&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

  </pre>
<p>child.tpl</p>
<pre class="programlisting">

{extends file="parent.tpl"} 
{block name="title" prepend}
Page Title
{/block}

  </pre>
<p>The result would look like</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Title - Page Title&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

</pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id366814"></a><p class="title"><b>Example 7.17. Append <code class="varname">{block}</code> example</b></p>
<div class="example-contents">
<p>parent.tpl</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{block name="title"} is my title{/block}&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

  </pre>
<p>child.tpl</p>
<pre class="programlisting">

{extends file="parent.tpl"} 
{block name="title" append}
Page Title
{/block}

  </pre>
<p>The result would look like</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Page title is my titel&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

</pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id366856"></a><p class="title"><b>Example 7.18. <code class="varname">{$smarty.block.child}</code> example</b></p>
<div class="example-contents">
<p>parent.tpl</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{block name="title"}The {$smarty.block.child} was inserted here{/block}&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

  </pre>
<p>child.tpl</p>
<pre class="programlisting">

{extends file="parent.tpl"} 
{block name="title"}
Child Title
{/block}

  </pre>
<p>The result would look like</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;The Child Title was inserted here&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

</pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id366897"></a><p class="title"><b>Example 7.19. <code class="varname">{$smarty.block.parent}</code> example</b></p>
<div class="example-contents">
<p>parent.tpl</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;{block name="title"}Parent Title{/block}&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

  </pre>
<p>child.tpl</p>
<pre class="programlisting">

{extends file="parent.tpl"} 
{block name="title"}
You will see now - {$smarty.block.parent} - here
{/block}

  </pre>
<p>The result would look like</p>
<pre class="programlisting">

&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;You will see now - Parent Title - here&lt;/title&gt;
  &lt;/head&gt;
&lt;/html&gt;

</pre>
</div>
</div>
<br class="example-break"><p>
  See also
  <a class="link" href="advanced.features.template.inheritance.html" title="Template Inheritance">Template Inheritance</a>,
  <a class="link" href="language.variables.smarty.html#language.variables.smarty.block.parent" title="{$smarty.block.parent}"><em class="parameter"><code>$smarty.block.parent</code></em></a>,
  <a class="link" href="language.variables.smarty.html#language.variables.smarty.block.child" title="{$smarty.block.child}"><em class="parameter"><code>$smarty.block.child</code></em></a>,
  and <a class="link" href="language.function.extends.html" title="{extends}"><code class="varname">{extends}</code></a>
 </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.assign.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.builtin.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.call.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{assign} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {call}</td>
</tr>
</table>
</div>
</body>
</html>
